package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private Button btnJumpToBambooGarden;
    private TextView txtBambooNum;
    private TextView txtTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        txtTitle.setText("首页");

        btnJumpToBambooGarden.setOnClickListener(view -> {
            Intent intent = new Intent(this, BambooGardenActivity.class);
            startActivityForResult(intent, 1);
        });
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == 2) {
            if (data != null) {
                String bambooNum = data.getStringExtra("bambooNum");   // 获取回传数据
                txtBambooNum.setText("摘到" + bambooNum + "个");
            }
        }
    }

    private void initView() {
        btnJumpToBambooGarden = findViewById(R.id.btn_jumpToBambooGarden);
        txtBambooNum = findViewById(R.id.txt_bambooNum);
        txtTitle = findViewById(R.id.txt_title);
    }

}